﻿#region Using

using System;
using System.Collections.Generic;

#endregion

namespace Vk.Methods.Common
{
    /// <summary>
    ///    List with an additional field TotalCount
    /// </summary>
    /// <typeparam name="T">List item's type</typeparam>
    public class ListCount<T> : List<T>
    {

        /// <summary>
        ///    Total count of items exist for the request.
        /// </summary>
        public int TotalCount { get; set; }

        public ListCount(int count, List<T> list)
        {
            TotalCount = count;
            AddRange(list);
        }

        public ListCount(ApiNode result, Func<ApiNode, T> selector)
        {
            TotalCount = result.Int("count").Value;

            foreach (var apiNode in result.SelectNode("items").ChildNodes)
            {
                Add(selector(apiNode));
            }
        }
    }
}